package com.hcc.repository.test.domain.listener;

import com.hcc.repository.extension.listener.RepoEntityPropSetListener;
import com.hcc.repository.test.domain.enums.ProductStatusEnum;
import com.hcc.repository.test.domain.po.ProductPo;

/**
 * ProductStatusNameWriteBackListener
 *
 * @author hushengjun
 * @date 2023/8/9
 */
public class ProductStatusNameWriteBackListener implements RepoEntityPropSetListener<ProductPo> {

    @Override
    public boolean test(Object entity, Object value, String propName, String columnName) {
        if (!ProductPo.class.equals(entity.getClass())) {
            return false;
        }
        if (!ProductStatusEnum.class.equals(value.getClass())) {
            return false;
        }

        return true;
    }

    @Override
    public void beforePropSet(ProductPo entity, String propName, Object propVal) {
        entity.setProductStatusName(((ProductStatusEnum)propVal).getName());
    }

}
